<?php
session_start();
if (isset($_POST['save'])){
   $cat=$_POST['category'];
	$title=$_POST['title'];
	$content=$_POST['content'];
	$dt=$_POST['date_time'];
	

	mysql_connect("localhost","root","");
	mysql_select_db("csf");

	$path = "../../img/uploads";
	$valid_formats = array ("jpg","png","gif","bmp","JPG","PNG","GIF","BMP");
	$name = $_FILES ['image'] ['name'];
	$size = $_FILES ['image'] ['size'];

	if (strlen ( $name )) {
		list ( $txt, $ext ) = explode ( ".", $name );
		if (in_array ( $ext, $valid_formats )) {

			if ($size < (1024*1024*5)) {

					
				$actual_image_name = time () . substr ( str_replace ( " ", "_", $txt ), 5 ) . "." . $ext;
				$tmp = $_FILES ['image'] ['tmp_name'];
					
				$sql=mysql_query("INSERT INTO events(id,catagory, title, content, date_time, image) VALUES(null, '$cat','$title','$content','$dt','$actual_image_name')");
					
				if ($sql) {
					$moveFile = move_uploaded_file ( $tmp,$path.$actual_image_name );
					if(!$moveFile){
						echo mysql_error();}

				}else {
					echo "NOT MOVED".mysql_error();
				}
			} else {
				echo "Image file size max 1 MB";
					
			}
		} else {
			echo "Invalid file format..";

		}
	} else {
		echo "string lenght is too short";
	}

}
	




?>